/**
 * Created by xuhenian on 2016/7/21.
 * jQuery plugs template
 */


import $ = require('jquery');
var plug_name = 'popup', plug_version = '0.1.0';

class jQplug {
  plugName: string = plug_name;
  version: string = plug_version;
  defaults: Object = {};
  config: any;
  $context: JQuery;

  /**
   * 构造函数
   * @param el
   * @param options
   */
  constructor(el: HTMLElement, options?: Object) {
    this.$context = $(el);
    this.config = $.extend(true, {}, this.defaults, options);
    $.data(el, 'ZTE_' + plug_name, this);
    this.init();
    this.initEvent();
  }

  /**
   * 初始化元素
   */
  private init() {
  }

  /**
   * 初始化事件绑定
   */
  private initEvent() {
  }

  setConfig(options: Object) {
    this.config = $.extend(true, {}, this.defaults, options);
  }
}

$[plug_name] = jQplug;
$.fn[plug_name] = function (options?: Object) {
  options = options || {};
  if (typeof options === 'object') {
    return (<any>this).each(function () {
      var $plug: jQplug = $(this).data('ZTE_' + plug_name);
      if ($plug === undefined) {
        new jQplug(this, options);//创建插件
      } else {
        $plug.setConfig(options);//设置参数
      }
    })
  } else {
    //在此定义更多参数类型
  }
};

export = function (el: any, options?: Object) {
  return $(el)[plug_name](options);
};
